//
//  BiBillManageViewController.m
//  TrunkIndustryManageSystem
//
//  Created by 李璐西 on 15/5/5.
//  Copyright (c) 2015年 李璐西. All rights reserved.
//

#import "BiBillManageViewController.h"

#import "BiCarLiscenceComEntity.h"
#import "BiCarLicense.h"
#import "BICarLicenseType.h"

@interface BiBillManageViewController ()<UITableViewDelegate>{

    __weak IBOutlet UIScrollView *_ScrollView;
    
}

//车主
//整车类型
@property (weak, nonatomic) IBOutlet UITextView *textVReasons;
@property (weak, nonatomic) IBOutlet UILabel *labMemberName;
@property (weak, nonatomic) IBOutlet UILabel *labWholeCarSalePrice;
@property (weak, nonatomic) IBOutlet UILabel *labVin;
@property (weak, nonatomic) IBOutlet UILabel *labAnnouncementModel;

@property (weak, nonatomic) IBOutlet UILabel *labEarnMemberPrice;
@property (weak, nonatomic) IBOutlet UILabel *labEarnCostPrice;
@property (weak, nonatomic) IBOutlet UILabel *labEarnDetectionPrice;
@property (weak, nonatomic) IBOutlet UILabel *labEarnManagementPrice;
@property (weak, nonatomic) IBOutlet UILabel *labEarnServicePrice;
@property (weak, nonatomic) IBOutlet UILabel *labEarnAgencyPrice;
@property (weak, nonatomic) IBOutlet UILabel *labEarnTotalPrice;

@property (weak, nonatomic) IBOutlet UILabel *labSaleAdvisorName;
@property (weak, nonatomic) IBOutlet UILabel *labHandlerName;
@property (weak, nonatomic) IBOutlet UILabel *labHandlerPerformance;
@property (weak, nonatomic) IBOutlet UILabel *labTransactorName;
@property (weak, nonatomic) IBOutlet UILabel *labTransactorPerformance;
@property (weak, nonatomic) IBOutlet UILabel *labInfoPifuPersonName;
@property (weak, nonatomic) IBOutlet UILabel *labJiaokuanPifuTime;


@end

@implementation BiBillManageViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setNavBackBtn];
    [self setNavBarTitle:@"开缴款单审批"];
    [self setNavBarWithHidden:NO];
    
    _ScrollView.contentSize = CGSizeMake(MAIN_SCREEN_WIDTH, 930);
    
    self.textVReasons.layer.borderColor = [UIColor colorWithRed:204.0/255.0 green:204.0/255.0 blue:204.0/255.0 alpha:100.0].CGColor;
    self.textVReasons.layer.borderWidth = 0.5;
    [self dataFill];
}

- (void)dataFill {
    if (self.cEntity) {
        _labMemberName.text = self.cEntity.Carlisce.memberName;
        _labWholeCarSalePrice.text = self.cEntity.Carlisce.wholeCarSalePrice;
        _labVin.text = self.cEntity.Carlisce.vin;
        _labAnnouncementModel.text = self.cEntity.Carlisce.announcementModel;
        
        _labEarnMemberPrice.text = self.cEntity.CarlisceType.earnMemberPrice;
        _labEarnCostPrice.text = self.cEntity.CarlisceType.earnCostPrice;
        _labEarnDetectionPrice.text = self.cEntity.CarlisceType.earnDetectionPrice;
        _labEarnManagementPrice.text = self.cEntity.CarlisceType.earnManagementPrice;
        _labEarnServicePrice.text = self.cEntity.CarlisceType.earnServicePrice;
        _labEarnAgencyPrice.text = self.cEntity.CarlisceType.earnAgencyPrice;
        _labEarnTotalPrice.text = self.cEntity.CarlisceType.earnTotalPrice;
        
        _labSaleAdvisorName.text = self.cEntity.Carlisce.saleAdvisorName;
        _labHandlerName.text = self.cEntity.Carlisce.handlerName;
        _labHandlerPerformance.text = self.cEntity.Carlisce.handlerPerformance;
        _labTransactorName.text = self.cEntity.Carlisce.transactorName;
        _labTransactorPerformance.text = self.cEntity.Carlisce.transactorPerformance;
        
//        车主
//        整车类型
//        批准人
//        批准时间
        if ([self.cEntity.Carlisce.jiaokuanPifuPersonName  isEqual: @""]) {
            _labInfoPifuPersonName.text = [BiUserEntity sharedInstance].name;
        }else {
           _labInfoPifuPersonName.text = self.cEntity.Carlisce.jiaokuanPifuPersonName;
        }

        if ([self.cEntity.Carlisce.jiaokuanPifuTime  isEqual: @""]) {
                   _labJiaokuanPifuTime.text = [BiUtil stringFromFomate:[NSDate date] formate:@"yyyy-MM-dd hh:mm"];
        }else {
            _labInfoPifuPersonName.text = self.cEntity.Carlisce.jiaokuanPifuTime;
        }

        _textVReasons.text = self.cEntity.Carlisce.infoRejectReason;
    }
    
}

- (IBAction)btnCheckClick:(UIButton *)sender {
    
    NSString * stutas = nil;
    if (1 == sender.tag) {
        //批准
        stutas = @"1";
    }else if (0 == sender.tag){
        //驳回
        stutas = @"0";
    }
    
    
//    NSString * jiaokuanPifuPersonName = !self.cEntity.Carlisce.jiaokuanPifuPersonName?@"":self.cEntity.Carlisce.jiaokuanPifuPersonName;
    
    NSString * infoRejectReason = !self.cEntity.Carlisce.infoRejectReason?@"":self.cEntity.Carlisce.infoRejectReason;
    
    NSDictionary * paraDic = nil;
    
    if (1 == sender.tag) {
        
        paraDic = [NSDictionary dictionaryWithObjectsAndKeys:self.cEntity.Carlisce.ID,@"id",
                                  @"2",@"licenseStatus",
                                  stutas,@"status",nil];
        
    }else if (0 == sender.tag) {
        
        paraDic = [NSDictionary dictionaryWithObjectsAndKeys:self.cEntity.Carlisce.ID,@"id",
                                  @"2",@"licenseStatus",
                                  stutas,@"status",
                                  // @"dfsdf",@"jiaokuanPifuPersonName",
                                  infoRejectReason,@"infoRejectReason",nil];
        
    }
    
    [[BiNetEngine shareInstance] requestDocBillCheck:self paraDict:paraDic];
    
    [self asyshowHUDView:WAITING CurrentView:self];
    
}

#pragma -mark Net Delegate
- (void)onNetEngineResponse:(int)tag entity:(id)entity userInfo:(NSDictionary *)userInfo
{
    
    [self removeHUDView:self];
    
    NSDictionary * entity_ = (NSDictionary *)entity;
    
    [self showMessage:entity_[@"result_info"]];
    
    if ([entity_[@"response_status"] integerValue] != 200) {
        
        return;
        
    }
    
    switch (tag) {
        case NET_GET_CAR_DOC_CHECK:
        {
            [self.navigationController popViewControllerAnimated:YES];
            
        }
            break;
            
        default:
            break;
    }
    
    
    
}
- (void)onNetEngineResponseFail:(int)tag entity:(id)entity userInfo:(NSDictionary *)userInfo
{
    [self removeHUDView:self];
    
}
@end
